﻿' Developer Express Code Central Example:
' How to customize the Edit Appointment form to show custom fields
' 
' This example illustrates the use of a custom form to enable the end-user to edit
' custom fields. The custom form is invoked instead of the default one by handling
' the SchedulerControl.EditAppointmentFormShowing
' (ms-help://DevExpress.NETv8.2/DevExpress.XtraScheduler/DevExpressXtraSchedulerSchedulerControl_EditAppointmentFormShowingtopic.htm)
' event.
' 
' See also:
' For a simple application that enables you to handle custom
' fields, see the http://www.devexpress.com/scid=E2782 article.
' 
' You can find sample updates and versions for different programming languages here:
' http://www.devexpress.com/example=E152


Partial Public Class ActivityEditForm
    Inherits DevExpress.XtraScheduler.UI.AppointmentForm

    Public Property LockGroup As Boolean = False

    Public Sub New(ByVal control As SchedulerControl, ByVal apt As Appointment)
        MyBase.New(control, apt)
    End Sub

    Protected Overrides Sub UpdateForm()
        ' Required to initialize controls that represent custom fields
        InitializeComponent()
        MyBase.UpdateForm()
        'AddHandler edtLabel.SelectedValueChanged, AddressOf titi
    End Sub

    'Protected Overridable Sub titi(ByVal sender As Object, ByVal e As System.EventArgs)

    'End Sub
    Protected Overrides Sub OnOkButton()
        MyBase.OnOkButton()
        Me.Controller.IsAppointmentChanged()

    End Sub

    Protected Overrides Sub OnDeleteButton()
        MyBase.OnDeleteButton()
    End Sub

    Protected Overrides Sub OnRecurrenceButton()
        MyBase.OnRecurrenceButton()
    End Sub

    Protected Overrides Function CreateController(ByVal control As SchedulerControl, ByVal apt As Appointment) As AppointmentFormController
        Return New ActivityAppFormController(control, apt)
    End Function

    Protected Overrides Sub UpdateCustomFieldsControls()
        MyBase.UpdateCustomFieldsControls()
        mslGroup.EditValue = (CType(MyBase.Controller, ActivityAppFormController)).CustomGroupId
    End Sub

    Private Sub btnRecurrence_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        OnRecurrenceButton()
    End Sub

    Private Sub AppointmentEditForm_Load(sender As Object, e As EventArgs) Handles Me.Load

        mslGroup.Enabled = Not LockGroup

        mslGroup.QueryName = "LOV_AppointmentGroup"
        mslGroup.InitMetaQuery()
        mslGroup.EditValue = (CType(MyBase.Controller, ActivityAppFormController)).CustomGroupId
        mslGroup.Refresh()
        '
        mslCategory.QueryName = "LOV_AppointmentCategory"
        mslCategory.InitMetaQuery()
        mslCategory.EditValue = (CType(MyBase.Controller, ActivityAppFormController)).CustomCategoryId
        mslCategory.Refresh()
        '
        mslClasse.QueryName = "LOV_AppointmentClass"
        mslClasse.InitMetaQuery()
        mslClasse.EditValue = (CType(MyBase.Controller, ActivityAppFormController)).CustomClassId
        mslClasse.Refresh()
        '
        mslType.QueryName = "LOV_AppointmentType"
        mslType.InitMetaQuery()
        mslType.EditValue = (CType(MyBase.Controller, ActivityAppFormController)).CustomTypeId
        mslType.Refresh()
        '
    End Sub

    Private Sub mslGroup_EditValueChanged(sender As Object, e As EventArgs) Handles mslGroup.EditValueChanged
        Dim tmpGuid As Guid
        If mslGroup.EditValue IsNot Nothing AndAlso Guid.TryParse(mslGroup.EditValue.ToString, tmpGuid) Then
            CType(MyBase.Controller, ActivityAppFormController).CustomGroupId = tmpGuid
        Else
            CType(MyBase.Controller, ActivityAppFormController).CustomGroupId = Nothing
        End If
    End Sub
    Private Sub mslCategory_EditValueChanged(sender As Object, e As EventArgs) Handles mslCategory.EditValueChanged
        Dim tmpGuid As Guid
        If mslCategory.EditValue IsNot Nothing AndAlso Guid.TryParse(mslCategory.EditValue.ToString, tmpGuid) Then
            CType(MyBase.Controller, ActivityAppFormController).CustomCategoryId = tmpGuid
        Else
            CType(MyBase.Controller, ActivityAppFormController).CustomCategoryId = Nothing
        End If
    End Sub
    Private Sub mslClasse_EditValueChanged(sender As Object, e As EventArgs) Handles mslClasse.EditValueChanged
        Dim tmpGuid As Guid
        If mslClasse.EditValue IsNot Nothing AndAlso Guid.TryParse(mslClasse.EditValue.ToString, tmpGuid) Then
            CType(MyBase.Controller, ActivityAppFormController).CustomClassId = tmpGuid
        Else
            CType(MyBase.Controller, ActivityAppFormController).CustomClassId = Nothing
        End If
    End Sub
    Private Sub mslType_EditValueChanged(sender As Object, e As EventArgs) Handles mslType.EditValueChanged
        Dim tmpGuid As Guid
        If mslType.EditValue IsNot Nothing AndAlso Guid.TryParse(mslType.EditValue.ToString, tmpGuid) Then
            CType(MyBase.Controller, ActivityAppFormController).CustomTypeId = tmpGuid
        Else
            CType(MyBase.Controller, ActivityAppFormController).CustomTypeId = Nothing
        End If
    End Sub
End Class
